////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                            //
//                                                         WNProject                                                          //
//                                                                                                                            //
//            This file is distributed under the BSD 2-Clause open source license. See License.txt for details.               //
//                                                                                                                            //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once

#ifndef __WN_CONTAINERS_RESOURCE_POINTER_H__
#define __WN_CONTAINERS_RESOURCE_POINTER_H__

#include "WNCore/inc/WNPlatform.h"
#include "WNCore/inc/WNTypes.h"
#include "WNCore/inc/WNAssert.h"
#include "WNCore/inc/WNAtomic.h"
#include "WNMemory/inc/WNAllocation.h"

namespace WNContainers {
    template <typename Type>
    class WNResourcePointer {
    public:
        WNResourcePointer();
        WNResourcePointer(Type* _resource);
        WNResourcePointer(const WNResourcePointer<Type>& _resourcePointer);
        ~WNResourcePointer();

        WNResourcePointer<Type>& operator = (const WNResourcePointer<Type>& _resourcePointer);

        Type* operator -> ();
        const Type* operator -> () const;
        Type& operator * ();

    private:
        WN_VOID RemoveRef();

    private:
        Type* mResource;
    };

    template <typename Type>
    WNResourcePointer<Type> WNAllocateResource();

    template <typename Type, typename Parameter>
    WNResourcePointer<Type> WNAllocateResource(Parameter& p);
}

#include "WNContainers/inc/WNResourcePointer.inl"

#endif // __WN_CONTAINERS_RESOURCE_POINTER_H__